/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package eproject.utilitity;

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 *
 * @author khiemtd
 */
public class StringUtils {

    public static String md5Encrypted(String input) throws NoSuchAlgorithmException {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] messageDigest = md.digest(input.getBytes());
            BigInteger number = new BigInteger(1, messageDigest);
            String hashtext = number.toString(16);
            while (hashtext.length() < 32) {
                hashtext = "0" + hashtext;
            }
            return hashtext;
        
    }

    public static String convertToStringWithEncoding(String input, String encoding) throws UnsupportedEncodingException {
       return new String(input.getBytes(encoding), encoding);       
    }
    
    public static boolean isNullOrEmpty(String input){
        return input == null || input.isEmpty() || input.trim().isEmpty();
    }
}
